package com.design.common;


import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class JsonResult<T>{
    private Integer code;
    private String message;
    private T data;

    public static <T> JsonResult<T> success(){
        return new JsonResult<>(ResponseStatus.SUCCESS.getCode(),ResponseStatus.SUCCESS.getMsg(),null);
    }

    public static <T> JsonResult<T> success(T data) {
        return new JsonResult<>(ResponseStatus.SUCCESS.getCode(),ResponseStatus.SUCCESS.getMsg(), data);
    }

    //自定义消息
    public static <T> JsonResult<Void> success(String message) {
        return new JsonResult<>(ResponseStatus.SUCCESS.getCode(), message, null);
    }

    public static <T> JsonResult<Void> success(int code, String message) {
        return new JsonResult<>(code, message, null);
    }

    public static <T> JsonResult<T> fail() {
        return new JsonResult<>(40000, "fail", null);
    }
    public static <T> JsonResult<T> fail(String message) {
        return new JsonResult<>(ResponseStatus.FAIL.getCode(), message, null);
    }

    public static <T> JsonResult<T> error(String message) {
        return new JsonResult<>(50000, message, null);
    }

    public static <T> JsonResult<T> error(int code, String message) {
        return new JsonResult<>(code, message, null);
    }

    public static <T> JsonResult<T> warn(String message) {
        return new JsonResult<>(30000, message, null);
    }
}
